#include "ImagePreloading.h"

ImagePreloading::ImagePreloading()
{
}

ImagePreloading::~ImagePreloading()
{
}
void ImagePreloading::loadImage(QStringList filePaths, int index)
{
    if (image_pre.isNull() && image_next.isNull())
    {
        QImage image;
        image.load(filePaths[0]);
        emit imageLoaded(image);
    }
    else if (index < cur_index)
    {
        emit imageLoaded(image_pre);
    }
    else if (index > cur_index)
    {
        emit imageLoaded(image_next);
    }
    cur_index = index;
    int pre_index = cur_index - 1;
    if (pre_index < 0)
        pre_index = filePaths.size() - 1;
    int next_index = cur_index + 1;
    image_pre.load(filePaths[pre_index % filePaths.size()]);
    image_next.load(filePaths[next_index % filePaths.size()]);
}
void ImagePreloading::clearImage()
{
    image_pre = QImage();
    image_next = QImage();
}
